<?php
declare (strict_types = 1);

namespace app\mulitlevel\controller;

use app\mulitlevel\model\Category;

/**
 * 多级联动
 * Class Index
 * @package app\mulitlevel\controller
 */
class Index
{
    public function index()
    {
        return '您好！这是一个[mulitlevel]示例应用';
    }

    /**
     * 多级联动
     * 默认查询一级分类
     */
    public function category(){
        # 查询一级分类
        $data = Category::where('pid','=',0)->select();

        return view('/category',['data' => $data]);
    }

    /**
     * 获取分类的接口
     */
    public function getCategory(){
        $pid = request()->get('pid',0);
        # 查询一级分类
        $data = Category::where('pid','=',$pid)->select()->toArray();

        return json(['code' => 200,'msg' => 'ok','data' => $data]);
    }
    /**
     * 1.0
     * =============
     * 2.0
     */

    /**
     * 获取分类的接口
     */
    public function getCategoryV2(){
        $pid = request()->get('pid',0);
        # 查询一级分类
        $data = Category::where('pid','=',$pid)->select()->toArray();

        return json(['code' => 200,'msg' => 'ok','data' => $data]);
    }
}
